package 剑指offer_leetcode;

import java.util.Stack;

/**
 * JZ9用两个栈实现队列
 */
public class 剑指Offer09_用两个栈实现队列 {
    class CQueue {
        private Stack<Integer> s1 ;
        private Stack<Integer> s2;
        public CQueue() {
            this.s1 = new Stack<>();
            this.s2 = new Stack<>();
        }

        public void appendTail(int value) {
            s1.push(value);
        }

        public int deleteHead() {
            while(!s1.isEmpty())
                s2.push(s1.pop());
            int val = -1;
            if(!s2.isEmpty())
                val = s2.pop();
            while(!s2.isEmpty())
                s1.push(s2.pop());
            return val;
        }
    }

}
